// pages/back-up/back-up.js
const app=getApp();
Page({

  /**
   * 页面的初始数据
   */
  
  data: {
    titleName: app.data.url +"zhongxue/teacher/beiwang",
    delbeiwang: app.data.url +"zhongxue/teacher/delbeiwang",
    shuju:{},
    backArr: [
    ],
    newUrl: [
      app.data.url +"uploads/laoshi/50.png"
    ]
  },
  skip:function(){
    wx.navigateTo({
      url: '/pages/memo/memo',
    })
  },


  /**
  * 修改
  */
  edit:function(e){
    // console.log(e);
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/xgmemo/xgmemo?id=' + id,
    })
  },

  /**
   * 删除
   */
  del:function(e){
    // console.log(e);
    var that = this;
    var id = e.currentTarget.dataset.id;
    var user = wx.getStorageSync('newuser');
    var token = user.token;
    var shenhe = user.shenhe;
    wx.request({
      url: that.data.delbeiwang,
      data:{id:id,token:token,shenhe:shenhe},
      method:'post',
      success:function(res){
        var data = res.data
        // console.log(data);
        if(data.code == 200){
          wx.showToast({
            title: '删除成功',
            icon: 'none',
          })
          that.onShow();
        }else{
          wx.showToast({
            title: '删除失败',
            icon: 'none',
          })
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    var user = wx.getStorageSync("newuser");
    // if (!user) {
    //   wx.redirectTo({
    //     url: '/pages/register/register',
    //   })
    // }
    var token = user.token;
    var shenhe = user.shenhe;
    // console.log(token)
    wx.request({
      url: that.data.titleName,
      data: { token: token, shenhe: shenhe },
      method: 'post',
      success: function (res) {
        console.log(res)
        var data = res.data.data;
        if (res.data.code == 200) {
          // console.log(data)
          var shuju = data.data;
          // console.log(shuju);
          that.setData({ shuju: shuju });
        } else {
          wx.navigateTo({
            url: '/pages/register/register',
            success: function (res) { },
            fail: function (res) { },
            complete: function (res) { },
          })
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    // this.onShow();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})